package com.jx.service.impl;

import com.jx.dao.HomeMapper;
import com.jx.dto.FloorDto;
import com.jx.pojo.CarouselBanner;
import com.jx.pojo.Floor;
import com.jx.pojo.GuessLike;
import com.jx.service.HomeService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class HomeServiceImpl implements HomeService {
    @Autowired
    private HomeMapper homeMapper;

    /**
     * 获取轮播图数据
     * @return
     */
    @Override
    public List<CarouselBanner> getCarouselBannerList() {
        List<CarouselBanner> carouselBanners = homeMapper.getCarouselBannerList();
        return carouselBanners;
    }

    /**
     * 获取guess_like数据
     * @return
     */
    @Override
    public List<GuessLike> getGuessLikeList() {
        List<GuessLike> guessLikes = homeMapper.getGuessLikeList();
        return guessLikes;
    }

    /**
     * 获取floor数据
     * @return
     */
    @Override
    public List<FloorDto> getFloorList() {
        // 获取所有的floor数据
        List<Floor> floorList = homeMapper.getFloorList();
        // 将floor数据转换为dto类型
        List<FloorDto> floorDtoList = floorList.stream().map(floor->{
            FloorDto floorDto = new FloorDto();
            // 将floor中的属性复制到floorDto中
            BeanUtils.copyProperties(floor,floorDto,"keywords","navList","carouselList","recommendList");
            // 将flool中的keywords、navlist、carouseList、recommendList等属性转换为数组
            floorDto.setKeywords(floor.getKeywords().split(","));
            floorDto.setNavList(floor.getNavList().split(","));
            floorDto.setCarouselList(floor.getCarouselList().split(","));
            floorDto.setRecommendList(floor.getRecommendList().split(","));
            // 返回floorDto
            return floorDto;
        }).collect(Collectors.toList());
        return floorDtoList;
    }


}
